package library.and.xps.com.step.view.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.view.View;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;

import com.zhy.autolayout.AutoRelativeLayout;

import java.io.File;
import java.util.List;

import library.and.xps.com.step.R;
import library.and.xps.com.step.m.netapi.OkHttpClientUtils;
import library.and.xps.com.step.util.CommonUtils;
import library.and.xps.com.step.view.base.BaseActivity;

public class TeamInfoActivity extends BaseActivity implements View.OnClickListener {
    int REQUEST_CODE_CHOOSE = 0;
    List<Uri> mSelected;
    ImageView iv_orgini_sign;
    File file;
    AutoRelativeLayout actionbar_al,ar_team_pass,ar_orgin_info;
    Switch aSwitch;
    String UPLOAD_ORG_SIGN = "UPLOAD_ORGINIZATION_SIGN";
    @Override
    protected int getLayout() {
        return R.layout.activity_teaminfo;
    }

    @Override
    protected void setData() {
        File videoFile = new File(Environment.getExternalStorageDirectory() + File.separator + "/Video.mp4");
        //upload(videoFile);
    }

    @Override
    protected void init() {
        iv_orgini_sign = r2v(R.id.iv_orgini_sign);
        ar_team_pass = r2v(R.id.ar_team_pass);
        ar_orgin_info = r2v(R.id.ar_orgin_info);
        ar_team_pass.setOnClickListener(this);
        iv_orgini_sign.setOnClickListener(this);
        ar_orgin_info.setOnClickListener(this);
        ((TextView)r2v(R.id.actionbar_tv_title)).setText("团队信息");
        r2v(R.id.actionbar_iv_back).setOnClickListener(this);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_CHOOSE && resultCode == RESULT_OK) {
            file = new File(CommonUtils.getRealFilePath(this, mSelected.get(0)));

            //upload(file);
        }
    }

//    void upload(File file) {
//        showDialog();
//        final File[] files = {file};
//        final String[] filenames = {"file_upload"};
//        try {
//            OkHttpClientUtils.postUploadFilesAsync(TeamInfoActivity.this, URLConstants.FILE.FileUpload, files, filenames, new RequestCallback() {
//                @Override
//                public void onFailure(Request request, Exception e) {
//                    e.printStackTrace();
//                    dissmisDialog();
//                }
//
//                @Override
//                public void onResponse(ResponceWrapper response) {
//                    if (response.getResponcecode() == 200) {
//                        dissmisDialog();
//                        runOnUiThread(new Runnable() {
//                            @Override
//                            public void run() {
//                                Glide.with(TeamInfoActivity.this).load(mSelected.get(0))
//                                        .placeholder(R.drawable.walk)
//                                        .bitmapTransform(new RoundedCornersTransformation(TeamInfoActivity.this, 10, 0, RoundedCornersTransformation.CornerType.ALL))
//                                        .into(iv_orgini_sign);
//                            }
//                        });
//                    }
//                }
//
//                @Override
//                public void onStart() {
//
//                }
//            }, UPLOAD_ORG_SIGN);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkHttpClientUtils.cancelCall(UPLOAD_ORG_SIGN);
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.iv_orgini_sign:
                break;
            case R.id.actionbar_iv_back:
                finish();
                break;
            case R.id.ar_team_pass:
                startActivity(new Intent(this,ResetTeamPassActivity.class));
                break;
            case R.id.ar_orgin_info:
                startActivity(new Intent(this,TeamDescriptionAvtivity.class));
                break;
        }
    }
}
